package GameEngine.Gui.Event;

import java.util.ArrayList;

public class KeyEventProcessor {

	private ArrayList<KeyEvent> events = new ArrayList<KeyEvent>();
	private ArrayList<IKeyEventListener> listeners = new ArrayList<IKeyEventListener>();

	public KeyEventProcessor() {
		super();
		// TODO etwas Sinnvolles hier
	}

	public void add(KeyEvent e) {
		if (e != null) {
			events.add(e);
		}
	}
	
	public void registerKeyEventListener(IKeyEventListener el) {
		listeners.add(el);
	}
	
	// send events to the sketch
	public void sendEvents() {
		for (int i = 0; i < events.size(); i++) {
			KeyEvent ke = events.get(i);
			processKeyEvent (ke);
		}
		events.clear();
	}


	private void processKeyEvent(KeyEvent ke) {
		for (IKeyEventListener l: listeners) {
			l.onKeyPressed(ke);
		}
	}
}
